<template>
	<view style="width: 100%;  background-color: 	#F5F5F5;
	display: flex;
	align-items: center;
	flex-direction: column;"
	>
	<view class="cha">
		<input type="text" placeholder="请输入司机姓名…" style="width:335px;height:40px;background:rgba(249,249,249,1);border-radius:8px;margin-top: 10px;margin-left: 10px;padding-left: 10px;" v-model="name"/>
		<view style="margin-top: 5px;display: flex;align-items: center;justify-content: center;margin-left: 10px;">
			<input type="text" placeholder="请输入电话号…" style="width:240px;height:40px;background:rgba(249,249,249,1);border-radius:8px;padding-left: 10px;" v-model="phone"/>
			<button style="width:90px;height:40px;background:rgba(4,42,88,1);border-radius:8px;color: #FFFFFF;" @click="query">查询</button>
		</view>
	</view>
	<view style="margin-top: 120px;">
		<view class="Driver" v-for="(v,i) in list" :key="i" @click="Drive(i)">
			<view style="width: 114px;margin-left: 20px;
			display: flex;
			align-items: center;
			justify-content: space-between;"
			>
				<text style="color: #042A58;">{{v.drivername}}</text>
				<view>	
				<text v-if="v.authstatus==1">未认证</text>
				<text v-if="v.authstatus==2">已认证</text>
			<!-- 	<text v-if="mydata.authstatus == 3">已过期</text>
				<text v-if="mydata.authstatus == 4">快过期</text>
				<text v-if="mydata.authstatus == 5">已认证</text>
				<text v-if="mydata.authstatus == ''">未知</text>
				<text v-if="mydata.authstatus == null">认证失败</text> -->
				</view>
			</view>
			<text style="width: 116px; margin-right: 20px; ">{{v.drivermobile}}</text>
		</view>
		</view>
		<view class="loading" >{{ loadingTxt }}</view>
	</view>
</template>

<script>
	import {ajaxs} from '../../apis.js';
	var page=1
	export default {
		data() {
			return {
				list:[],
				abc:"123",
				name:"",
				phone:"",
				loadingTxt: '加载更多',
			}
		},

			onLoad() {
				var that=this
				this.drives()
		},
		onPullDownRefresh() {
				this.drives()
		},
		onReachBottom() {
			this.getdrives()
		},
		methods: {
			drives(){
				page=1
				var that=this
				ajaxs({
				      url: "/v1/capacity/list",
						method:"post",
						data:{
							drivername:that.name,
							drivermobile:that.phone,
							offset: page,
							limit: 20
						},
				      success(res) {
				  that.list=res.data.list
				  uni.stopPullDownRefresh()
				   uni.hideNavigationBarLoading()
				   page++
				      //请求成功的处理
				      }
				    })
			},
			getdrives(){
				this.loadingTxt="加载中"
				var that=this
				ajaxs({
				      url: "/v1/capacity/list",
						method:"post",
						data:{
							drivername:that.name,
							drivermobile:that.phone,
							offset: page,
							limit: 20
						},
				      success(res) {
						  if(page>res.data.pageInfo.pages){
						  	that.loadingTxt = '已经全部加载';
						  	uni.hideNavigationBarLoading();
						  	return false;
						  }
				 uni.hideNavigationBarLoading()
				 that.list = that.list.concat(res.data.list);
				 uni.stopPullDownRefresh()
				  page++
				      //请求成功的处理
				      }
				    })
			},
			query(){
				var that=this
				ajaxs({
					url: '/v1/capacity/list',
					method: 'post',
					data: {
						drivername:that.name,
						drivermobile:that.phone,
					},
					success(res) {
						console.log(res)
						that.list = res.data.list
				}
				});
			},
			Drive(i){
				uni.setStorage({
				key:"cart",
				data:{
					name:this.list[i].drivername,
							state:this.list[i].authstatus,
							Telephone:this.list[i].drivermobile,
							id:this.list[i].id
				}
				})
				var pages = getCurrentPages();
				 var prevPage = pages[pages.length - 2]; //上一个页面
				  //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
				 prevPage.setData({
				      mydata: {
				       name:this.list[i].drivername,
				       		state:this.list[i].authstatus,
				       		Telephone:this.list[i].drivermobile,
				       		id:this.list[i].id
				      }
				    })
				    wx.navigateBack({//返回
				      delta: 1
				    })
			}
		}
	}
</script>

<style>
.Driver{
	width: 355px;
	height: 60px;
	background-image: url(../../static/img/bg_dk1.png);
	color: #627995;
	font-size: 18;
	display: flex;
	align-items: center;
	justify-content: space-around;
	margin-top: 10px;
}
.cha{
	width:355px;
	height:105px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	margin-top: 10px;
	position: fixed;
}
.loading {
	text-align: center;
	color: #888;
	margin-top: 10px;
	margin-bottom: 70px;
}
</style>
